home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_130 / qman / mandel.asm < prev    next >
Assembly Source File  |  1992-05-06  |  5KB  |  109 lines

  1. ****************************************************************************
  2. *
  3. *         Draws  a Row of Pixels in Mandelbrot Set
  4. *
  5. *         C must set the following variables prior to call:
  6. *                xptr   :  pointer to table of x-values 
  7. *                imagc  :  imaginary part of current pixel row
  8. *                bp1-4  :  pointers to the four bit planes
  9. *  
  10. *         Integers are 2**26 times the actual values in the complex plane
  11. *
  12. ****************************************************************************
  13.  
  14.             XDEF        _mandel              This tells C about us
  15.             SECTION     text,code
  16.  
  17. _mandel     movem.l     d2-d7/a2-a6,-(a7)    save registers
  18. setup       moveq       #8,d4                bit within screen byte
  19.             move.l      #639,pixct           pixel counter for current row
  20.             move.l      _xptr,a5              
  21.             move.l      _imagc,d6
  22.             move.l      _bp1,a0              
  23.             move.l      _bp2,a1
  24.             move.l      _bp3,a2
  25.             move.l      _bp4,a3
  26.   
  27. xloop       move.l      (a5)+,d5             move next x-value into D5
  28.             moveq       #79,d3               set counter to 79
  29.             clr.l       d0                   zero out real_z
  30.             clr.l       d2                   zero out imag_z
  31.  
  32. repeat      moveq       #13,d7               number of bits to shift
  33.             asr.l       d7,d0                divide real_z by 2**13
  34.             asr.l       d7,d2                divide imag_z by 2**13
  35.  
  36.             move.l      d0,d1                real_z
  37.             sub.w       d2,d0                real_z - imag_z
  38.             add.w       d1,d1                2 * real_z
  39.             muls        d1,d2                2 * real_z * imag_z
  40.             sub.w       d0,d1                real_z + imag_z
  41.             muls        d1,d0                real_z**2 - imag_z**2
  42.            
  43.             add.l       d5,d0                add real_c to get new real_z
  44.             move.l      d0,d7                create temp copy of real_z
  45.             bpl         pos_1                if real_z positive, do nothing
  46.             neg.l       d7                   take absolute value of real_z
  47. pos_1       add.l       d6,d2                add imag_c to get new imag_z
  48.             move.l      d2,d1                load working copy of imag_z
  49.             bpl         pos_2                if imag_z positive, do nothing
  50.             neg.l       d1                   take absolute value of imag_z
  51. pos_2       add.l       d1,d7                d7 contains the norm of z
  52.             subq        #1,d3                decrement counter by 1
  53.             beq         poke                 if 120 iters, draw the pixel
  54.             subi.l      #200000000,d7        reduce the norm by 200 million 
  55.             bmi         repeat               if z not exploding, continue
  56.             addq        #1,d3                increment counter by 1
  57.             asr.l       #3,d3                color is 1/8 number of iters
  58.             addq        #3,d3                range 3 to 12
  59.  
  60. poke        tst.l       d4                   examine bit within byte
  61.             bne         plane1               if not bit zero, poke planes
  62.             moveq       #8,d4                reset to bit 8 (next will be 7)
  63.             lea         1(a0),a0             incr addr within 1st bit plane
  64.             lea         1(a1),a1                              2nd
  65.             lea         1(a2),a2                              3rd
  66.             lea         1(a3),a3                              4th
  67. plane1      subq.l      #1,d4                decrement bit within byte by 1
  68.  
  69. nomenus     btst        d4,(a0)              if we've hit a menu-- STOP!
  70.             bne         nomenus
  71.             btst        d4,(a1)
  72.             bne         nomenus
  73.             btst        d4,(a2)
  74.             bne         nomenus
  75.             btst        d4,(a3)
  76.             bne         nomenus
  77.  
  78.             btst        #0,d3                examine 1st bit of color
  79.             beq         plane2               if bit off, leave screen alone
  80.             bset        d4,(a0)              turn current bit on in plane
  81. plane2      btst        #1,d3              
  82.             beq         plane3
  83.             bset        d4,(a1)
  84. plane3      btst        #2,d3
  85.             beq         plane4
  86.             bset        d4,(a2)
  87. plane4      btst        #3,d3
  88.             beq         next_x
  89.             bset        d4,(a3)
  90. next_x      subi.l      #1,pixct             decrement x counter
  91.             bpl         xloop                if not done with row, continue
  92.  
  93.             add.l       #80,_bp1             advance to next display line
  94.             add.l       #80,_bp2
  95.             add.l       #80,_bp3
  96.             add.l       #80,_bp4
  97.  
  98.             movem.l     (a7)+,d2-d7/a2-a6    restore registers
  99.           
  100.             rts
  101.  
  102.             SECTION     udata,bss      
  103.             XREF        _xptr,_imagc
  104.             XREF        _bp1,_bp2,_bp3,_bp4
  105. pixct       DS.L        1
  106.             END
  107.  
  108.